package com.hex.ds.hdtp.core.inf.dqc.repository.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hex.ds.hdtp.core.inf.common.page.Page;
import com.hex.ds.hdtp.core.inf.common.page.converter.IPageAndMyBatisPlusPageConverter;
import com.hex.ds.hdtp.core.inf.dqc.mapper.IDqcTaskMapper;
import com.hex.ds.hdtp.core.inf.dqc.po.DqcTaskPo;
import com.hex.ds.hdtp.core.inf.dqc.repository.IDqcTaskRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class DqcTaskRepository implements IDqcTaskRepository {

    private final IDqcTaskMapper dqcTaskMapper;

    private final IPageAndMyBatisPlusPageConverter pageConverter;

    /**
     * @Method queryById
     * @param pkId
     * @Return com.hex.ds.hdtp.core.inf.dqc.po.DqcTaskPo
     * @Description 通过ID查询
     * @Author Yin.Yang
     * @Date 2023/11/5 21:40
     * @Version V1.0
     */
    @Override
    public DqcTaskPo queryById(String pkId) {
        return dqcTaskMapper.selectById(pkId);
    }

    /**
     * @Method add
     * @param dqcTaskPo
     * @Return java.lang.Integer
     * @Description 新增任务
     * @Author Yin.Yang
     * @Date 2023/11/5 21:19
     * @Version V1.0
     */
    @Override
    public Integer add(DqcTaskPo dqcTaskPo) {
        return dqcTaskMapper.insert(dqcTaskPo);
    }

    /**
     * @Method modifyById
     * @param dqcTaskPo
     * @Return java.lang.Integer
     * @Description 通过ID修改
     * @Author Yin.Yang
     * @Date 2023/11/5 21:40
     * @Version V1.0
     */
    @Override
    public Integer modifyById(DqcTaskPo dqcTaskPo) {
        return dqcTaskMapper.updateById(dqcTaskPo);
    }

    /**
     * @Method removeById
     * @param pkId
     * @Return java.lang.Integer
     * @Description 通过主键删除
     * @Author Yin.Yang
     * @Date 2023/11/5 21:39
     * @Version V1.0
     */
    @Override
    public Integer removeById(String pkId) {
        return dqcTaskMapper.deleteById(pkId);
    }

    /**
     * @Method addWithBackPkId
     * @param dqcTaskPo
     * @Return java.lang.String
     * @Description 新增并返回主键
     * @Author Yin.Yang
     * @Date 2023/11/5 21:38
     * @Version V1.0
     */
    @Override
    public String addWithBackPkId(DqcTaskPo dqcTaskPo) {
        dqcTaskPo.setJobName(dqcTaskPo.getTableName());
        dqcTaskMapper.insert(dqcTaskPo);
        return dqcTaskPo.getPkId();
    }

    /**
     * @Method modifyRulesById
     * @Param dqcTaskPo
     * @Return java.lang.Integer
     * @Description 更新规则
     * @Author gj.xu
     * @Date 2023/12/27 14:20
     * @Version V2.0
     */
    @Override
    public Integer modifyRulesById(DqcTaskPo dqcTaskPo) {
        return dqcTaskMapper.modifyRulesById(dqcTaskPo);
    }

    /**
     * @Method queryListByPage
     * @param dqcTaskPo
     * @param page
     * @Return com.hex.ds.hdtp.core.inf.common.page.Page<com.hex.ds.hdtp.core.inf.dqc.po.DqcTaskPo>
     * @Description 分页查询
     * @Author Yin.Yang
     * @Date 2023/11/5 21:21
     * @Version V1.0
     */
    @Override
    public Page<DqcTaskPo> queryListByPage(DqcTaskPo dqcTaskPo, Page page) {
        final IPage tmpPageResult = dqcTaskMapper.queryListByPage(
                pageConverter.toMyBatisPlusPage(page)
                , dqcTaskPo
        );
        final List list = tmpPageResult.getRecords();
        final Page pageResult = pageConverter.toPage(tmpPageResult);
        return pageResult.setData(list);
    }
}
